#ifndef SECURITYTCPCOMMUNICATION_H
#define SECURITYTCPCOMMUNICATION_H

#include "CommunicationInterFace.h"

#include <QObject>
#include <QTcpSocket>
#include <QUdpSocket>

//这个类不会跟封装好加密的东西，加密由上层做，这个只是用来传输数据。
class securityTcpCommunication : public CommunicationInterface
{
    Q_OBJECT
public:
    securityTcpCommunication();
    void connect(const QString &hostAddress, const quint64 &hostPort) override;
    void sendData(const QByteArray &data) override;
    QByteArray readData() override;
    void disconnect() override;

protected slots:
    void onReadyRead() override;
    void onConnected() override;
    void onError(QAbstractSocket::SocketError socketError) override;
    void onDisconnected() override;
signals:

private:
    QTcpSocket tcpSocket;
    //接收数据的缓冲区
    QByteArray receiveBuffers[2]; // 两个接收缓冲区，一个用来接收，一个用来向上层传递数据
    QByteArray sendBuffers[2]; // 两个发送缓冲区
    QByteArray transBuffer;
    // //当前使用的缓冲区索引
    int currentReceiveBufferIndex;
    // int currentSendBufferIndex;

    //一次性接收的最大的数据大小是
    int expectedPacketSize = 2048;
};

#endif // SECURITYTCPCOMMUNICATION_H
